/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * Copyright 2008 Rhythm Computing All rights reserved.
 * 
 * Message.java	
 * @date: Oct 12, 2008
 * @author Michael J. Lee
 * 
 */
package com.rhythm.base;

import com.rhythm.commons.datetime.Time;

public class Message {

    /**
     * The default id for a message
     */
    public static final int DEFAULT_ID = 0;
    public static final String DEFAULT_GROUP = "";

    /**
     * Returns a new instance of a <code>Message</code> with the given id and
     * message.
     *
     * @param id an id
     * @param group
     * @param message a message for the reciepent
     * @return a new instance of a <code>Message</code> with the given id and
     * message.
     */
    public static Message of(int id, String group, String message) {
        return new Message(id, group, message);
    }

    /**
     * Returns a new instance of a <code>Message</code> with the given id and 
     * message.
     * 
     * @param id an id
     * @param message a message for the reciepent
     * @return a new instance of a <code>Message</code> with the given id and 
     * message.
     */
    public static Message of(int id, String message) {
        return new Message(id, DEFAULT_GROUP, message);
    }

    /**
     * Returns a new instance of a <code>Message</code> with the given message 
     * and a the default zero id
     * 
     * @param id an id
     * @param message a message for the reciepent
     * @return a new instance of a <code>Message</code> with the given id and 
     * message.
     */
    public static Message of(String message) {
        return new Message(DEFAULT_ID, DEFAULT_GROUP, message);
    }
    private final int id;
    private final String group;
    private final String message;
    private final long time;

    private Message(final int id, final String group, final String message) {
        this.id = id;
        this.group = group;
        this.message = message;
        this.time = Time.now();
    }

    /**
     * Returns the current id of the message
     * @return the current id of the message
     */
    public int getId() {
        return id;
    }

    /**
     * Returns a {@code String} that represents the {@code Message}'s group.
     * <br/><strong>NOTE<strong/><br/>
     * See the {@code DEFAULT_GROUP}  for default grouping on a {@code Message}
     * @return
     */
    public String getGroup() {
        return group;
    }

    /**
     * Returns a message
     * @return a message
     */
    public String getMessage() {
        return message;
    }

    /**
     * Returns the UTC milliseconds from the epoch when the message was created.
     * @return the UTC milliseconds from the epoch when the message was created
     */
    public long getTime() {
        return time;
    }

    /**
     * Forces a <code>IllegalArgumentException</code> of the give message. 
     * 
     * @throws java.lang.IllegalArgumentException guaranteed
     */
    public void toIllegalArgumentException() throws IllegalArgumentException {
        throw new IllegalArgumentException(message);
    }
}
